{extend name="adminblue/base" /}
{block name="resources"/}
<link rel="stylesheet" type="text/css" href="ADMIN_CSS/member_list.css" />

<style>
    .head-portrait{
        margin-top:15px;
    }
</style>

{/block}
{block name="main"}
<table class="mytable">
    <tr>
        <th width="20%" style="text-align: left;">
            <button class="btn-common-delete btn-small" onclick="batchDelete()" style="margin:0 5px 0 0 !important;">批量删除</button>
            <button class="btn-common btn-small" onclick="add_user()" style="margin:0 5px 0 0 !important;">添加客户经理</button>
        </th>

        <th>
            <!--<select id="level_name" class="select-common">-->
                <!--<option value ="-1">请选择会员等级</option>-->
            <!--</select>-->
            <input type="text" id ='search_text' placeholder="输入手机号/邮箱/客户经理昵称" class="input-common" />
            <input type="button" onclick="searchData()" value="搜索" class="btn-common" />
        </th>
    </tr>
</table>
<table class="table-class">
    <thead>
    <tr align="center">
        <th><input type="checkbox" onclick="CheckAll(this)"></th>
        <th style="width: 30%;text-align:left;">客户经理</th>
        <th>负责区域</th>
        <th>佣金</th>
        <th align="right">积分</th>
        <th align="right">账户余额</th>
        <th>注册&登录</th>
        <th>状态</th>
        <th style="width: 20%;">操作</th>
    </tr>
    </thead>
    <tbody id="productTbody">
    <!--<tr align="center">-->
        <!--<td>-->
            <!--<input name="sub" type="checkbox" value="7">-->
        <!--</td>-->
        <!--<td align="left">-->
            <!--<img src="/public/static/images/default_user_portrait.gif" class="head-portrait">-->
            <!--<div style="float:left;">-->
                <!--<label style="float:none;width:100%">用户名：<span>admin001</span>-->
                <!--</label>-->
                <!--<label style="float:none;width:100%">昵称：<span>麦兜</span>-->
                <!--</label><label style="float:none;width:100%">手机：<span>15290930800</span>-->
            <!--</label><label style="float:none;width:100%">邮箱：<span>1292446992@qq.com</span></label>-->
            <!--</div>-->
        <!--</td>-->
        <!--<td>周口市川汇区</td>-->
        <!--<td>¥1000</td>-->
        <!--<td align="right">0</td>-->
        <!--<td align="right">¥50000</td>-->
        <!--<td>注册时间 : 2018-05-23 17:21:56<br>最后登录 : 2018-05-23 17:21:56</td>-->
        <!--<td style="color:green;">正常</td>-->
        <!--<td>-->
            <!--<a href="http://www.maiyao.com/index.php?s=/admin/member/pointdetail&amp;member_id=7">积分明细</a>&nbsp;&nbsp;<a href="http://www.maiyao.com/index.php?s=/admin/member/accountdetail&amp;member_id=7">余额明细</a><br><a onclick="recharge_point(7,0)">积分调整</a>&nbsp;&nbsp;<a onclick="recharge_balance(7,0)">余额调整</a><br><a onclick="lockuser(7)">设置锁定&nbsp;&nbsp;&nbsp;</a><a onclick="modify_password(7)">重置密码</a><br><a onclick="modify_user(7)">修改</a>&nbsp;&nbsp;<a onclick="delete_user(7)">删除-->
    <!--</a>-->
        <!--<br>-->
    <!--</td>-->
    <!--</tr>-->
    </tbody>
</table>
<!-- 余额调整 -->
<div class="modal fade hide" id="recharge_balance" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h3>调整余额</h3>
            </div>
            <div class="modal-body">
                <div class="modal-infp-style">
                    <table>
                        <tr>
                            <td>当前余额</td>
                            <td colspan='3' id="current_balance" class="input-common" ></td>
                        </tr>
                        <tr>
                            <td>调整金额</td>
                            <td colspan='3' id="time"><input type="number" id="balance" class="input-common" />增加或减少</td>
                        </tr>
                        <tr>
                            <td>备注</td>
                            <td colspan='3' id="time"><textarea id="remark_balance" class="input-common"></textarea></td>
                        </tr>
                    </table>
                </div>
            </div>

            <div class="modal-footer">
                <input type="hidden" id="balance_id" />
                <button class="btn btn-primary" onclick="addAccount(2)">保存</button>
                <button class="btn" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>

</div>

<!-- 积分调整 -->
<div class="modal fade hide" id="recharge_point" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h3>调整积分</h3>
            </div>
            <div class="modal-body">
                <div class="modal-infp-style">
                    <table>
                        <tr>
                            <td>当前积分</td>
                            <td colspan='3' id="current_point" class="input-common"></td>
                        </tr>
                        <tr>
                            <td>调整积分</td>
                            <td colspan='3' id="time"><input type="number" id="point" class="input-common">增加或减少</td>
                        </tr>
                        <tr>
                            <td>备注</td>
                            <td colspan='3' id="time"><textarea id="remark_point" class="input-common"></textarea></td>
                        </tr>
                    </table>

                </div>
            </div>
            <div class="modal-footer">
                <input type="hidden" id="point_id" />
                <button class="btn btn-primary" onclick="addAccount(1)">保存</button>
                <button class="btn" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>

</div>

<!-- 添加会员 -->
<div class="modal fade hide" id="add_user" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h3>添加会员</h3>
            </div>
            <div class="modal-body">
                <div class="modal-infp-style">
                    <table class="modal-tab">
                        <tr>
                            <td style="width:20%;"><span class="required">*</span>用户名</td>
                            <td colspan='3'>
                                <input type="text" id="username" class="input-common" />
                                <span id="usernameyz"></span>
                                <input type="hidden" value="不存在" id="isset_username" class="input-common" />
                            </td>
                        </tr>
                        <tr>
                            <td><span class="required">*</span>登录密码</td>
                            <td colspan='3'><input type="password" id="password" class="input-common"></td>
                        </tr>
                        <tr>
                            <td style="width:22%;"><span class="required">*</span>昵称</td>
                            <td colspan='3'>
                                <input type="text" id="nickname" class="input-common" />
                            </td>
                        </tr>
                        <tr>
                            <td>手机号码</td>
                            <td colspan='3'><input type="text" id="telephone" class="input-common"/><span id="telephoneyz"></span></td>
                        </tr>
                        <tr>
                            <td>邮箱地址</td>
                            <td colspan='3'><input type="text" id="member_email" class="input-common" /><span id="member_emailyz"></span></td>
                        </tr>
                        <tr>
                            <td>负责区域</td>
                            <td colspan='3'><input type="text" id="leader_region" class="input-common" /><span id="leader_regionyz"></span></td>
                        </tr>
                        <tr>
                            <td>佣金设置</td>
                            <td colspan='3'><input type="text" id="leader_commission" class="input-common" /><span id="leader_commissionyz"></span></td>
                        </tr>
                        <tr>
                            <td>性别</td>
                            <td><label><input type="radio" checked="checked" name="sex" value="1"/>男&nbsp;&nbsp;</label><label><input name="sex" type="radio" value="2"/>女&nbsp;&nbsp;</label><label><input name="sex" type="radio" value="0"/>保密</label></td>
                        </tr>
                        <tr>
                            <td>账户状态</td>
                            <td><label><input type="radio" checked="checked" name="status" value="1"/>正常&nbsp;&nbsp;</label><label><input name="status" type="radio" value="0"/>锁定</label></td>
                        </tr>
                    </table>
                </div>
            </div>

            <div class="modal-footer">
                <button class="btn btn-primary" onclick="addUser()">保存</button>
                <button class="btn" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>

</div>

<input type="hidden" id="modify_uid"/>
<!-- 修改会员 -->
<div class="modal fade hide" id="modify_user" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

    <div class="modal-dialog" >
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">编辑会员</h4>
            </div>
            <div class="modal-body" style="min-height: 360px;">
                <div class="modal-infp-style">
                    <table class="modal-tab">
                        <tr style="height: 32px;">
                            <td style="width:20%"><span class="required">*</span>用户名</td>
                            <td colspan='3'>
                                <!-- 								<span id="modify_username"></span> -->
                                <input type="text" id="modify_username" class="input-common" />
                                <span id="modify_usernameyz"></span>
                                <input type="hidden" value="不存在" id="modify_isset_username"/>
                            </td>
                        </tr>
                        <tr>
                            <td style="width:20%">昵称</td>
                            <td colspan='3'><input type="text" id="modify_nickname"/></td>
                        </tr>
                        <tr>
                            <td style="width:20%">负责区域</td>
                            <td colspan='3'><input type="text" id="modify_region"/></td>
                        </tr>
                        <tr>
                            <td style="width:20%">佣金</td>
                            <td colspan='3'><input type="text" id="modify_commission"/></td>
                        </tr>
                        <tr>
                            <td>手机号码</td>
                            <td colspan='3'><input type="text" id="modify_telephone" value=""/><span id="modify_telephoneyz"></td>
                        </tr>
                        <tr>
                            <td>邮箱地址</td>
                            <td colspan='3'><input type="text" id="modify_member_email"/><span id="modify_member_emailyz"></td>
                        </tr>
                        <tr>
                            <td>性别</td>
                            <td id="sex"><label><input type="radio" name="sex" value="1"/>男&nbsp;&nbsp;</label><label><input name="sex" type="radio" value="2"/>女&nbsp;&nbsp;</label><label><input name="sex" type="radio" value="0"/>保密</label></td>
                        </tr>
                        <tr>
                            <td>账户状态</td>
                            <td id="status"><label><input type="radio" name="status" value="1"/>正常&nbsp;&nbsp;</label><label><input name="status" type="radio" value="0"/>锁定</label></td>
                        </tr>
                    </table>
                </div>
            </div>

            <div class="modal-footer">
                <input type="hidden" id="modify_username_hidden" />
                <button class="btn btn-info" onclick="modifyUser()" id="butSubmit"  style="display:inline-block;">保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>

</div>

<!-- 修改会员密码 -->
<div class="modal fade hide" id="modify_password" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">重置密码</h4>
            </div>
            <div class="modal-body">
                <div class="modal-infp-style">
                    <table class="modal-tab">
                        <tr>
                            <td style="width:20%">密码</td>
                            <td colspan='3'><input type="text" id="modify_passwords" class="input-common"/></td>
                        </tr>
                    </table>
                </div>
            </div>

            <div class="modal-footer">
                <input type="hidden" id="modify_userid" />
                <button class="btn btn-primary" onclick="modifypassword()">保存</button>
                <button class="btn" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>

</div>
{/block}
{block name="script"}

<script type="text/javascript">
    function LoadingInfo(page_index) {
        var search_text = $("#search_text").val();
        var levelid = $("#level_name").val();
        $.ajax({
            type : "post",
            url : "{:__URL('ADMIN_MAIN/member/clientManager')}",
            data : {
                "page_index" : page_index, "page_size" : $("#showNumber").val(), "search_text" : search_text,"levelid":levelid
            },
            success : function(data) {
                var html = '';
                if (data["data"].length > 0) {
                    for (var i = 0; i < data["data"].length; i++) {
                        html += '<tr align="center">';
                        html += '<td><input name="sub" type="checkbox" value="'+ data["data"][i]["uid"]+'" ></td>';
                        html += '<td align="left">';

                        if(data["data"][i]["user_headimg"] ==""){
                            html += '<img src="__STATIC__/images/default_user_portrait.gif" class="head-portrait" />';
                            html += '<div style="float:left;">';
                            if(data["data"][i]["user_name"] == '' || data["data"][i]["user_name"] == null){
// 							html+='用户名:'+'--'+'<br/>';
                                html += '<label style="float:none;width:100%">用户名：<span>--</span></label>';
                            }else{
// 							html+='用户名:'+data["data"][i]["user_name"] +'<br/>';
                                html += '<label style="float:none;width:100%">用户名：<span>' + data["data"][i]["user_name"] + '</span></label>';
                            }
                            if (data["data"][i]["user_tel"] == null || "" == data["data"][i]["user_tel"]) {
                                if (data["data"][i]["user_email"] == null || "" == data["data"][i]["user_email"]) {
// 								html += '昵称 : '+data["data"][i]["nick_name"] +'<br/>'+'手机 :'+'--'+'<br/>'+'邮箱 : '+'--';
                                    html += '<label style="float:none;width:100%">昵称: <span>' + data["data"][i]["nick_name"] + '</span></label>';
                                    html += '<label style="float:none;width:100%"><span>手机：--</span></label>';
                                    html += '<label style="float:none;width:100%"><span>邮箱：--</span></label>';
                                } else {
// 								html += '昵称 : '+data["data"][i]["nick_name"] +'<br/>'+'手机 : '+'--'+'<br/>'+'邮箱 : '+data["data"][i]["user_email"];
                                    html += '<label style="float:none;width:100%">昵称 :<span>' + data["data"][i]["nick_name"] + '</span></label>';
                                    html += '<label style="float:none;width:100%"><span>手机：--</span></label>';
                                    html += '<label style="float:none;width:100%"><span>邮箱：' + data["data"][i]["user_email"] + "</span></label>";
                                }
                            } else {
                                if (data["data"][i]["user_email"] == null || "" == data["data"][i]["user_email"]) {
// 								html += '昵称 : '+data["data"][i]["nick_name"] +'<br/>'+'手机 : '+data["data"][i]["user_tel"]+'<br/>'+'邮箱 : '+'--';
                                    html += '<label style="float:none;width:100%">昵称：<span>' + data["data"][i]["nick_name"] + "</span></label>";
                                    html += '<label style="float:none;width:100%">手机：<span>' + data["data"][i]["user_tel"] + "</span></label>";
                                    html += '<label style="float:none;width:100%">邮箱：<span>--</span></label>';
                                } else {
// 								html += '昵称 : '+data["data"][i]["nick_name"] +'<br/>'+'手机 : '+data["data"][i]["user_tel"]+'<br/>'+'邮箱 : '+data["data"][i]["user_email"];
                                    html += '<label style="float:none;width:100%">昵称：<span>' + data["data"][i]["nick_name"] + '</span></label>';
                                    html += '<label style="float:none;width:100%">手机：<span>' + data["data"][i]["user_tel"] + '</span></label>';
                                    html += '<label style="float:none;width:100%">邮箱：<span>' + data["data"][i]["user_email"] + "</span></label>";
                                }
                            }
                        }else{
                            html += '<img src="'+__IMG(data["data"][i]["user_headimg"])+'" class="head-portrait" />';
                            if (data["data"][i]["user_tel"] == null || "" == data["data"][i]["user_tel"]) {
                                if (data["data"][i]["user_email"] == null || "" == data["data"][i]["user_email"]) {
// 								html += '昵称 : '+data["data"][i]["nick_name"] +'<br/>'+'手机 : '+'--'+'<br/>'+'邮箱 : '+'--';
                                    html += '<label style="float:none;width:100%">昵称：<span>' + data["data"][i]["nick_name"] + '</span></label>';
                                    html += '<label style="float:none;width:100%">手机：<span>--</span></label>';
                                    html += '<label style="float:none;width:100%">邮箱：<span>--</span></label>';
                                } else {
// 								html += '昵称 : '+data["data"][i]["nick_name"] +'<br/>'+'手机 : '+'--'+'<br/>'+'邮箱 : '+data["data"][i]["user_email"];
                                    html += '<label style="float:none;width:100%">昵称：<span>' + data["data"][i]["nick_name"] + '</span></label>';
                                    html += '<label style="float:none;width:100%">手机：<span>--</span></label>';
                                    html += '<label style="float:none;width:100%">邮箱：<span>' + data["data"][i]["user_email"] + '</span></label>';
                                }
                            } else {
                                if (data["data"][i]["user_email"] == null || "" == data["data"][i]["user_email"]) {
// 								html += '昵称 : '+data["data"][i]["nick_name"] +'<br/>'+'手机 : '+data["data"][i]["user_tel"]+'<br/>'+'邮箱 : '+'--';
                                    html += '<label style="float:none;width:100%">昵称：<span>' + data["data"][i]["nick_name"] + '</span></label>';
                                    html += '<label style="float:none;width:100%">手机：<span>' + data["data"][i]["user_tel"] + '</span></label>';
                                    html += '<label style="float:none;width:100%">邮箱：<span>--</span></label>';
                                } else {
// 								html += '昵称 : '+data["data"][i]["nick_name"] +'<br/>'+'手机 : '+data["data"][i]["user_tel"]+'<br/>'+'邮箱 : '+data["data"][i]["user_email"];
                                    html += '<label style="float:none;width:100%">昵称：<span>' + data["data"][i]["nick_name"] + '</span></label>';
                                    html += '<label style="float:none;width:100%">手机：<span>' + data["data"][i]["user_tel"] + '</span></label>';
                                    html += '<label style="float:none;width:100%">邮箱：<span>' + data["data"][i]["user_email"] + '</span></label>';
                                }
                            }
                        }
                        html += '</div>';
                        html += '</td>';
                        if(data["data"][i]["region"]==null || data["data"][i]["region"]==undefined){
                            html += '<td>--</td>';
                        }else{
                            html += '<td>' + data["data"][i]["region"] + '</td>';
                        }
                        html += '<td align="right">' + data["data"][i]["commission"] + '</td>';
                        html += '<td align="right">' + data["data"][i]["point"] + '</td>';
                        html += '<td align="right">'+'¥'+ data["data"][i]["balance"] +'</td>';
                        html += '<td>' +'注册时间 : '+ timeStampTurnTime(data["data"][i]["reg_time"]) +'<br>'+'最后登录 : '+ timeStampTurnTime(data["data"][i]["current_login_time"])+'</td>';
                        html += data["data"][i]["user_status"] == 0 ? '<td style="color:red;">锁定</td>' : '<td style="color:green;">正常</td>';
                        html += '<td><a href="'+__URL('ADMIN_MAIN/member/pointdetail?member_id='+ data['data'][i]['uid'])+'">积分明细</a>&nbsp;&nbsp;';
                        html += '<a href="'+__URL('ADMIN_MAIN/member/accountdetail?member_id='+ data['data'][i]['uid'])+'">余额明细</a><br/>';
                        html += '<a onclick="recharge_point('+ data["data"][i]["uid"]+','+ data["data"][i]["point"] +')">积分调整</a>&nbsp;&nbsp;';
                        html += '<a onclick="recharge_balance('+ data["data"][i]["uid"]+','+data["data"][i]["balance"]+')">余额调整</a><br/>';

                        if(data["data"][i]["is_system"] != 1){
                            if(data["data"][i]["user_status"] == 0){
                                html += '<a onclick="unlockuser('+ data["data"][i]["uid"]+')">设置解锁&nbsp;&nbsp;&nbsp;</a>';
                            }else{
                                html += '<a onclick="lockuser('+ data["data"][i]["uid"]+')">设置锁定&nbsp;&nbsp;&nbsp;</a>';
                            }
                            html += '<a onclick="modify_password('+ data["data"][i]["uid"]+')">重置密码</a><br/>';

                            html += '<a onclick="modify_user('+ data["data"][i]["uid"]+')">修改</a>&nbsp;&nbsp;<a onclick="delete_user('+ data["data"][i]["uid"]+')">删除</a><br/>';

                        }
                        html += '</td>'
                        html += '</tr>';
                    }
                } else {
                    html += '<tr align="center"><td colspan="9">暂无符合条件的数据记录</td></tr>';
                }
                $(".table-class tbody").html(html);
                initPageData(data["page_count"],data['data'].length,data['total_count']);
                $("#pageNumber").html(pagenumShow(jumpNumber,$("#page_count").val(),{$pageshow}));
            }
        });
    }

    //全选
    function CheckAll(event){
        var checked = event.checked;
        $(".table-class tbody input[type = 'checkbox']").prop("checked",checked);
    }

    function searchData(){
        LoadingInfo(1);
    }

    //锁定会员
    function lockuser(uid){
        $.ajax({
            type : "post",
            url : "{:__URL('ADMIN_MAIN/member/memberlock')}",
            data : { "id" : uid },
            success : function(data) {
                if (data["code"] > 0) {
                    LoadingInfo(getCurrentIndex(uid,'#productTbody'));
                    showTip(data['message'],'success');
                }else{
                    showTip(data['message'],'error');
                }
            }
        });
    }

    //解锁会员
    function unlockuser(uid){
        $.ajax({
            type : "post",
            url : "{:__URL('ADMIN_MAIN/member/memberunlock')}",
            data : { "id" : uid },
            success : function(data) {
                if (data["code"] > 0) {
                    LoadingInfo(getCurrentIndex(uid,'#productTbody'));
                    showTip(data['message'],'success');
                }else{
                    showTip(data['message'],'error');
                }
            }
        });
    }

    //添加会员弹出
    function add_user(){
        $("#add_user").modal("show");
    }

    //积分充值
    function recharge_point(uid,point){
        $("#recharge_point").modal("show");
        $("#point_id").val(uid);
        $("#current_point").text(point);
    }
    //余额充值
    function recharge_balance(uid,balance){
        $("#recharge_balance").modal("show");
        $("#balance_id").val(uid);
        $("#current_balance").text(balance);
    }

    //充值
    function addAccount(type){
        var curr_obj = "";
        if(type == 1){
            var id = $("#point_id").val();
            var num = $("#point").val();
            var current_point = $("#current_point").text();
            var point = (parseInt(current_point) + parseInt(num));
            if(num == ''){
                showTip('积分不能为空','warning');
                return false;
            }
            var text = $("#remark_point").val();
            if(parseInt(point) < 0){
                showTip('积分不能为负数','warning');
                return false;
            }
            curr_obj = "recharge_point";
        }else{
            var id = $("#balance_id").val();
            var num = $("#balance").val();
            var current_balance = $("#current_balance").text();
            var balance = (parseInt(current_balance) + parseInt(num));
            if(num == ''){
                showTip('余额不能为空','warning');
                return false;
            }
            var text = $("#remark_balance").val();
            if(parseInt(balance) < 0){
                showTip('余额不能为负数','warning');
                return false;
            }
            curr_obj = "recharge_balance";
        }
        $.ajax({
            type : "post",
            url : "{:__URL('ADMIN_MAIN/member/addmemberaccount')}",
            data : {
                "id" : id,
                "type" : type,
                "num" : num,
                "text" : text
            },
            success : function(data) {
                if (data["code"] > 0) {
                    LoadingInfo(getCurrentIndex(id,'#productTbody'));
                    showTip(data['message'],'success');
                    $("#"+curr_obj).modal("hide");
                }else{
                    showTip(data['message'],'error');
                }
            }
        });
    }

    function checkUserName(username){
        var flag = true;
        $.ajax({
            type: "GET",
            url: "{:__URL('ADMIN_MAIN/member/check_username')}",
            async : false,
            data: {"username":username},
            success: function(data){
                if(data){
                    flag = false;
                    $("#username").css("border","1px solid red");
                    $("#usernameyz").css("color","red").text("用户名已存在");
                    $("#isset_username").attr("value","存在");
                }
            }
        });
        return flag;
    }

    function checkMobile(mobile){
        var flag = false;
        $.ajax({
            type: "post",
            url: "{:__URL('ADMIN_MAIN/member/checkUserInfoIsExist')}",
            async : false,
            data: {"info":mobile,"type":"mobile"},
            success: function(data){
                if(data){
                    flag = true;
                }
            }
        });
        return flag;
    }

    function checkEmail(email){
        var flag = false;
        $.ajax({
            type: "post",
            url: "{:__URL('ADMIN_MAIN/member/checkUserInfoIsExist')}",
            async : false,
            data: {"info":email,"type":"email"},
            success: function(data){
                if(data){
                    flag = true;
                }
            }
        });
        return flag;
    }

    //添加客户经理
    function addUser(){
        var username = $("#username").val();
        var nickname = $("#nickname").val();
        var password = $("#password").val();
        var tel = $("#telephone").val();
        var email = $("#member_email").val();
        var region = $("#leader_region").val();
        var commission = $("#leader_commission").val();
        var sex = $("input[name='sex']:checked").val();
        var status = $("input[name='status']:checked").val();

        if (username == '') {
            showTip('用户名不能为空','warning');
            return;
        }
        if (region == '') {
            showTip('负责区域不能为空','warning');
            return;
        }

        if (leader_commission == '') {
            showTip('佣金不能为空','warning');
            return;
        }
        if(!checkUserName(username)){
            showTip('用户名已存在','warning');
            return;
        }

        if (password == null || password.length < 6) {
            showTip('密码必须不小于6位！','warning');
            return;
        }
        if (nickname == '') {
            showTip('昵称不能为空','warning');
            return;
        }
        if(tel.length > 0){
            if(!(/^1(3|4|5|7|8)\d{9}$/.test(tel))){
                showTip("手机号码有误，请重填",'warning');
                return;
            }
            if(checkMobile(tel)){
                showTip('该手机号码已存在','warning');
                return;
            }
        }
        if(email.length > 0){
            if(!(/^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/.test(email))){
                showTip('邮箱错误,请重填','warning');
                return;
            }
            if(checkEmail(email)){
                showTip('该邮箱已存在','warning');
                return;
            }
        }
        $.ajax({
            type : "post",
            url : __URL("ADMIN_MAIN/member/addclientmanager"),
            data : {
                'username' : username,
                'nickname' :nickname,
                'password' : password,
                'member_level' : "",
                'region':region,
                'commission' :commission,
                'tel' : tel,
                'email' : email,
                'sex' : sex,
                'status' : status
            },
            success : function(data) {
                if (data['code'] > 0) {
                    showTip(data['message'],'success');
                    $("#add_user").modal("hide");
                    LoadingInfo(getCurrentIndex(1,'#productTbody'));
                } else {
                    showTip(data['message'],'error');
                    flag = false;
                }
            }
        });
    }
    //修改会员弹出
    function modify_user(uid){
        var id = parseInt(uid);
        $("#modify_user").modal("show");
        $.ajax({
            type : "post",
            url : "{:__URL('ADMIN_MAIN/member/getclientmanagerdetail')}",
            data : { 'uid':id, },
            success : function(data) {
                //alert(JSON.stringify(data['user_name']));
                $("#modify_uid").val(data.uid);
                if(data['user_name']!=''){
                    $("#modify_username").val(data.user_name);
                    $("#modify_username").attr('disabled',true);
                }

                $("#modify_nickname").val(data.nick_name);
                //$("#modify_password").val(data.user_password);
                $("#modify_username_hidden").val(data.user_name);
                $("#modify_telephone").val(data.user_tel);
                $("#modify_member_email").val(data.user_email);

                $("#modify_region").val(data.region);
                $("#modify_commission").val(data.commission);

                $("#modify_telephone").attr("old-value", data.user_tel);
                $("#modify_member_email").attr("old-value", data.user_email);

                $("#sex").find("input[value="+data.sex+"]").attr("checked",true);
                $("#status").find("input[value="+data.user_status+"]").attr("checked",true);
            }
        });
    }

    //重置密码弹出
    function modify_password(uid){
        $("#modify_password").modal("show");
        $("#modify_userid").val(uid);
    }

    //修改密码提交
    function modifypassword(){
        var uid = $("#modify_userid").val();
        var password = $("#modify_passwords").val();
        if (password == null || password.length < 6) {
            showTip('密码必须不小于6位！','warning');
            return false;
        }
        $.ajax({
            type : "post",
            url : "{:__URL('ADMIN_MAIN/member/updatememberpassword')}",
            data : {
                'uid':uid,
                'user_password' :password
            },
            success : function(data) {
                if (data['code'] > 0) {
                    showTip('修改成功','success');
                    LoadingInfo(getCurrentIndex(uid,'#productTbody'));
                    $("#modify_password").modal("hide");
                } else {
                    showTip('修改失败','error');
                    flag = false;
                }
            }
        });
    }

    function delete_user(uid){
        $( "#dialog" ).dialog({
            buttons: {
                "确定": function() {
                    $.ajax({
                        type : "post",
                        url : "{:__URL('ADMIN_MAIN/member/deletemember')}",
                        data : { "uid" : uid.toString() },
                        dataType : "json",
                        success : function(data) {
                            if(data["code"] > 0 ){
                                LoadingInfo(getCurrentIndex(uid.toString(),'#productTbody'));
                                showTip(data["message"],'success');
                                $("#chek_all").prop("checked", false);
                            }else{
                                showTip(data["message"],'error');
                            }
                        }
                    });
                    $(this).dialog('close');
                },
                "取消,#e57373": function() {
                    $(this).dialog('close');
                },
            },
            contentText:"删除会员同时会删除会员相关账户信息，确定要删除吗？",
        });
    }

    ////修改会员
    function modifyUser(){
        var uid = $("#modify_uid").val();
        var nickname = $("#modify_nickname").val();
        var username = $("#modify_username").val();

        var tel = $("#modify_telephone").val();
        var old_tel = $("#modify_telephone").attr("old-value");

        var email = $("#modify_member_email").val();
        var old_email = $("#modify_member_email").attr("old-value");

        var region = $("#modify_region").val();
        var commission = $("#modify_commission").val();

        var sex = $("input[name='sex']:checked").val();
        var status = $("input[name='status']:checked").val();

        if(nickname == ""){
            showTip("昵称不能为空","warning");
            $("#modify_nickname").focus();
            return;
        }

        if (username == '') {
            showTip('用户名不能为空','warning');
            return;
        }
        if (region == '') {
            showTip('负责区域不能为空','warning');
            return;
        }
        if (commission == '') {
            showTip('佣金不能为空','warning');
            return;
        }
        if(tel.length > 0){
            if(!(/^1(3|4|5|7|8)\d{9}$/.test(tel))){
                showTip("手机号码有误，请重填",'warning');
                return false;
            }
            if(tel != old_tel){
                if(checkMobile(tel)){
                    showTip('该手机号码已存在','warning');
                    return;
                }
            }
        }
        if(email.length > 0){
            if(!(/^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/.test(email))){
                showTip('邮箱错误,请重填','warning');
                return false;
            }
            if(email != old_email){
                if(checkEmail(email)){
                    showTip('该邮箱已存在','warning');
                    return;
                }
            }
        }
        $.ajax({
            type : "post",
            url : "{:__URL('ADMIN_MAIN/member/updateclientmanager')}",
            data : {
                'uid':uid,
                'user_name' :username,
                'nick_name' : nickname,
                'region' : region,
                'commission' : commission,
                'tel' : tel,
                'email' : email,
                'sex' : sex,
                'status' : status
            },
            success : function(data) {
                if (data['code'] > 0) {
                    showTip(data['message'],'success');
                    LoadingInfo(getCurrentIndex(uid,'#productTbody'));
                    $("#modify_user").modal("hide");
                } else {
                    showTip(data['message'],'error');
                    flag = false;
                }
            }
        });
    }
    //批量删除
    function batchDelete() {
        var uid= new Array();
        $("#productTbody input[type='checkbox']:checked").each(function() {
            if (!isNaN($(this).val())) {
                uid.push($(this).val());
            }
        });
        if(uid.length ==0){
            $( "#dialog" ).dialog({
                buttons: {
                    "确定,#e57373": function() {
                        $(this).dialog('close');
                    }
                },
                contentText:"请选择需要操作的记录",
                title:"消息提醒",
            });
            return false;
        }
        delete_user(uid);
    }

    /**
     * 会员数据导出
     */
    function dataExcel(){
        var search_text = $("#search_text").val();
        var levelid = $("#level_name").val();
        window.location.href=__URL("ADMIN_MAIN/member/memberDataExcel?search_text="+search_text+"&levelid="+levelid);
    }
</script>
{/block}